﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.ETL.DataServiceInterface
{
    public static class ExtDSAdapterFactory
    {
        public static IExtDSAdapter Create(string assemblyName, string typeName)
        {

            string assemblyFolder = string.Format("{0}ExtDS\\", System.Configuration.ConfigurationManager.AppSettings["AssemblyFolder"]);
            string filePath = string.Format("{0}{1}.dll", assemblyFolder, assemblyName);
            try
            {
                Assembly assembly = Assembly.Load(System.IO.File.ReadAllBytes(filePath));
                Type type = assembly.GetType(typeName);

                return (IExtDSAdapter)assembly.CreateInstance(typeName);
            }
            catch(Exception ex)
            {
                return null;
            }
        }
    }
}
